package onion.molingo2o.activity.request;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.easemob.chatuidemo.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import onion.molingo2o.R;
import onion.molingo2o.adapter.OnionAdapter;
import onion.molingo2o.bean.RequestTopMenu;
import onion.molingo2o.views.GridViewWithHeaderAndFooter;

/**
 * Created by Administrator on 2015/11/12.
 */
public class MyRequeSettingsActivity extends BaseActivity {
    View headView;
    GridView gridView;
    GridViewWithHeaderAndFooter  gv_request_setting;
    OnionAdapter menuTopAdapter,menuBottomAdapter;
    List<RequestTopMenu>  listTop=new ArrayList<>();
    List<RequestTopMenu>  listBottom=new ArrayList<>();
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_myreqsettings);
        initTitle("", "常用需求设置", "");
        gv_request_setting= (GridViewWithHeaderAndFooter) findViewById(R.id.gv_request_setting);
        headView=View.inflate(this,R.layout.requestsetting_top,null);
        gridView= (GridView) headView.findViewById(R.id.gridView);
        menuTopAdapter=   new OnionAdapter(this,R.layout.item_smal_icon,listTop,new String[]{"title"},new String[]{"getIcon"});
        menuBottomAdapter=   new OnionAdapter(this,R.layout.item_smal_icon,listBottom,new String[]{"title"},new String[]{"getIcon"});
        gridView.setAdapter(menuTopAdapter);
        gv_request_setting.addHeaderView(headView);
        gv_request_setting.setAdapter(menuBottomAdapter);
        getTest();
        gv_request_setting.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                RequestTopMenu menu = listBottom.remove(position);
                listTop.add(menu);
                menuBottomAdapter.notifyDataSetChanged();
                menuTopAdapter.notifyDataSetChanged();
            }
        });
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                RequestTopMenu menu = listTop.remove(position);
                listBottom.add(menu);
                menuBottomAdapter.notifyDataSetChanged();
                menuTopAdapter.notifyDataSetChanged();
            }
        });
    }

    private void getTest() {
        for(int i=0;i<6;i++){
            listTop.add(new RequestTopMenu("http://b.hiphotos.baidu.com/image/pic/item/eac4b74543a9822666914cf48e82b9014b90eb95.jpg", "洗车"));
            listBottom.add(new RequestTopMenu("http://g.hiphotos.baidu.com/image/h%3D200/sign=16f4ef3e35adcbef1e3479069cae2e0e/6d81800a19d8bc3e7763d030868ba61ea9d345e5.jpg", "找小鸡"));
        }
    }


}
